package com.qy.sss.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.qy.common.AbstractController;
import com.qy.sss.service.SanshishuService;

import flexjson.JSONSerializer;

@Controller
@RequestMapping("/sanshishu")
public class SssController extends AbstractController{

	@Autowired
	public SanshishuService service;
	
	@RequestMapping("/list") 
	public String list(HttpServletRequest request,
			HttpServletResponse response,String nian,String yue,String ri,String shi){
		request.setAttribute("nian", nian);
		request.setAttribute("yue", yue);
		request.setAttribute("ri", ri);
		request.setAttribute("shi", shi);
		return "../../3s/result.jsp";
	}
	
	@RequestMapping("/process") 
	public void process(HttpServletRequest request,
			HttpServletResponse response,String nian,String yue,String ri,String shi,String bizflag){
		String ret = "";
		if(bizflag.equals("pre_a")){
			ret = service.qianshi_fulu(nian, yue);
		}else if(bizflag.equals("pre_b")){
			ret = service.qianshi_shouyi(nian, yue);
		}else if(bizflag.equals("pre_c")){
			ret = service.qianshi_shouming(nian, yue);
		}else if(bizflag.equals("pre_d")){
			ret = service.qianshi_tuohua(nian, yue);
		}else if(bizflag.equals("this_a")){
			ret = service.xianshi_minggong(nian, yue);
		}else if(bizflag.equals("this_b")){
			ret = service.xianshi_shengchen(nian, yue,ri,shi);
		}else if(bizflag.equals("this_c")){
			ret = service.xianshi_jiating(nian, yue);
		}else if(bizflag.equals("this_d")){
			ret = service.xianshi_guansha(nian, yue);
		}else if(bizflag.equals("this_e")){
			ret = service.xianshi_simasha(nian, yue);
		}else if(bizflag.equals("this_f")){
			ret = service.xianshi_shouming(nian, yue);
		}else if(bizflag.equals("this_g")){
			ret = service.xianshi_caiyun_jiankang(nian, yue);
		}else if(bizflag.equals("next_a")){
			ret = service.laishi_difang(nian, yue);
		}else if(bizflag.equals("next_b")){
			ret = service.laishi_mingyun(nian, yue);
		}else if(bizflag.equals("next_c")){
			ret = service.laishi_shengxiao(nian, yue);
		}
		printTextData(ret, response);
	}
	
	@RequestMapping("/selectTable") 
	public void selectTable(HttpServletRequest request,
			HttpServletResponse response,String table){
		List<Map<String,Object>> list = service.selectTable(table);
		printJsonObjectData(list, response);
	}
	
	@RequestMapping("/updateRow") 
	public void updateRow(HttpServletRequest request,
			HttpServletResponse response,String table,String id){
		String params[] = request.getParameterValues("params[]");
		printTextData(""+service.update(table, id, params),response);
	}
	
}
